package ru.st.selenium.dessignPatterns;

import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.LoadableComponent;
import org.junit.*;

public class Chapter2 extends LoadableComponent<Chapter2> {
	WebDriver selenium;
	
	@FindBy (how= How.NAME, using="verifybutton")
	WebElement verifybutton;
	
	public Chapter2(WebDriver selenium) {
		this.selenium = selenium;
		PageFactory.initElements(selenium, this);		
} 
	public boolean isButtonPresent (String button) {
		return selenium.findElements(By.xpath("//input[@id='" + button + "']")).size()>0;
	}
	@Override
	protected void isLoaded() throws Error {
	String url = selenium.getCurrentUrl();
	if(url != "http://book.theautomatedtester.co.uk/chapter2") {
		throw new RuntimeException("The wrong page has loaded");
	}
		
	}
	@Override
	protected void load() {
		selenium.get("http://book.theautomatedtesster.co.uk/chapter2");
			
		}
		
	}
